﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using super_scrable.Models;

namespace super_scrable.Views.Widgets
{
    public partial class LetterZone : UserControl
    {
        /*private int value;
        private char letter;*/
        private Boolean visibleLetter = true;

        public Boolean VisibleLetter
        {
            get { return visibleLetter; }
            set { visibleLetter = value; }
        }

        public char Letter
        {
            get {
                if (this.label_letter.Text != "")
                    return this.label_letter.Text[0];
                else
                    return ' ';
            }
            set
            {
                //letter = value;
                if (this.visibleLetter)
                    this.label_letter.Text = value.ToString();
            }
        }

        public int Value
        {
            get {
                try
                {
                    return int.Parse(this.label_value.Text);
                }
                catch (Exception e)
                {
                    return 0;
                }
            }
            set
            {
                if(this.visibleLetter)
                    this.label_value.Text = value.ToString();
            }
        }

        public LetterZone()
        {
            InitializeComponent();
            //this.Value = 0;
        }

        public LetterZone(char letter, int value)
        {
            this.Value = value;
            this.Letter = letter;
            InitializeComponent();
        }

        private void label_letter_MouseDown(object sender, MouseEventArgs e)
        {
            this.OnMouseDown(e);
        }

        public void resizeLabel()
        {
            this.SuspendLayout();
            int letter_height = (int)(this.Height * 0.40f);
            int value_height = (int)(this.Height * 0.21f);

            this.label_letter.Font = new Font("Microsoft Sans Serif", letter_height, System.Drawing.FontStyle.Bold);
            this.label_value.Font = new Font("Microsoft Sans Serif", value_height, System.Drawing.FontStyle.Bold);
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        public void showPiece() {
            if (this.visibleLetter) return;

            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Gameboard));
            this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("piece1.BackgroundImage")));
            /*this.label_value.Text = this.value.ToString();
            this.label_letter.Text = this.letter.ToString();*/
            this.visibleLetter = true;
        }

        public void hidePiece() {
            if (!this.visibleLetter) return;

            this.BackgroundImage = null;
            /*this.letter = '\0';
            this.value = 0;*/
            this.label_value.Text = "";
            this.label_letter.Text = "";
            this.visibleLetter = false;
        }
    }
}
